<template>
  <div class="dashboard-container">
    <!-- 数据概览卡片 -->
    <div class="statistics-row mb-20">
      <div v-for="(item, index) in statisticsData" :key="index" class="statistics-item">
        <el-card shadow="hover" class="statistics-card">
          <div class="icon-container" :style="{ backgroundColor: item.bgColor }">
            <el-icon :size="24" :color="item.iconColor">
              <component :is="item.icon" />
            </el-icon>
          </div>
          <div class="content">
            <div class="title">{{ item.title }}</div>
            <div class="value">{{ item.value }}</div>
            <div
              v-if="item.compare !== undefined"
              class="compare-text"
              :class="getCompareClass(item.compare)"
            >
              <el-icon v-if="item.compare > 0"><ArrowUp /></el-icon>
              <el-icon v-else-if="item.compare < 0"><ArrowDown /></el-icon>
              <span
                >{{ Math.abs(item.compare).toFixed(2) }}% 环比{{
                  item.compare > 0 ? '增长' : '下降'
                }}</span
              >
            </div>
          </div>
        </el-card>
      </div>
    </div>

    <!-- 设备选择器 -->
    <el-row :gutter="20" class="mb-20" style="margin-top: 20px">
      <el-col :span="24">
        <el-card shadow="hover">
          <div class="filter-container">
            <span class="filter-label">设备选择：</span>
            <el-select
              v-model="selectedDevice"
              placeholder="请选择设备"
              clearable
              @change="handleDeviceChange"
              style="width: 240px"
            >
              <el-option label="全部设备" value="" />
              <el-option
                v-for="device in deviceOptions"
                :key="device.deviceId"
                :label="device.deviceName"
                :value="device.deviceId"
              />
            </el-select>
          </div>
        </el-card>
      </el-col>
    </el-row>

    <!-- 图表和数据列表 -->
    <el-row :gutter="20">
      <!-- 左侧图表区域 -->
      <el-col :span="16">
        <!-- 能耗趋势图表 -->
        <el-card shadow="hover" class="mb-20">
          <template #header>
            <div class="card-header">
              <span>能耗数据趋势</span>
              <div class="chart-tabs">
                <el-radio-group
                  v-model="chartTimeRange"
                  size="small"
                  @change="handleChartRangeChange"
                >
                  <el-radio-button label="day">今日</el-radio-button>
                  <el-radio-button label="week">本周</el-radio-button>
                  <el-radio-button label="month">本月</el-radio-button>
                  <el-radio-button label="year">本年</el-radio-button>
                </el-radio-group>
              </div>
            </div>
          </template>
          <div ref="lineChartRef" style="height: 350px; width: 100%"></div>
        </el-card>

        <!-- 下方图表区域 -->
        <el-row :gutter="20">
          <el-col :span="12">
            <!-- 能耗环比分析 -->
            <el-card shadow="hover" class="mb-20">
              <template #header>
                <div class="card-header">
                  <span>能耗环比分析</span>
                  <el-tooltip content="显示当前周期与上一周期的能耗对比" placement="top">
                    <el-icon><InfoFilled /></el-icon>
                  </el-tooltip>
                </div>
              </template>
              <div ref="compareChartRef" style="height: 300px; width: 100%"></div>
            </el-card>
          </el-col>
          <el-col :span="12">
            <!-- 设备能耗统计饼图 -->
            <el-card shadow="hover" class="mb-20">
              <template #header>
                <div class="card-header">
                  <span>设备能耗分布</span>
                  <el-tooltip content="各设备能耗占比情况" placement="top">
                    <el-icon><PieChart /></el-icon>
                  </el-tooltip>
                </div>
              </template>
              <div ref="pieChartRef" style="height: 300px; width: 100%"></div>
            </el-card>
          </el-col>
        </el-row>
      </el-col>

      <!-- 右侧数据列表 -->
      <el-col :span="8">
        <el-card shadow="hover" style="height: calc(100% - 20px); overflow: auto">
          <template #header>
            <div class="card-header">
              <span>最近能耗数据上报</span>
              <el-button link type="primary" @click="getReportData">刷新</el-button>
            </div>
          </template>
          <el-table :data="reportList" style="width: 100%" size="small" v-loading="reportLoading">
            <el-table-column prop="deviceId" label="设备ID" width="100">
              <template #default="{ row }">
                <el-tooltip :content="getDeviceName(row.deviceId)" placement="top">
                  <span>{{ row.deviceId }}</span>
                </el-tooltip>
              </template>
            </el-table-column>
            <el-table-column prop="reportDataType" label="数据类型" width="80">
              <template #default="{ row }">
                <el-tag size="small">{{ getReportDataTypeLabel(row.reportDataType) }}</el-tag>
              </template>
            </el-table-column>
            <el-table-column prop="reportDataValue" label="数值" width="70" />
            <el-table-column prop="reportDataLevel" label="级别" width="70">
              <template #default="{ row }">
                <el-tag size="small" :type="getReportDataLevelType(row.reportDataLevel)">
                  {{ getReportDataLevelLabel(row.reportDataLevel) }}
                </el-tag>
              </template>
            </el-table-column>
            <el-table-column prop="reportDataTime" label="上报时间" min-width="140">
              <template #default="{ row }">
                {{ formatDate(row.reportDataTime) }}
              </template>
            </el-table-column>
          </el-table>
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>

<script lang="ts" setup>
import { ref, onMounted, onUnmounted, reactive } from 'vue'
import * as echarts from 'echarts'
import { getReportDataPage } from '@/api/energy/report'
import { getDeviceList } from '@/api/energy/device'
import { formatDate } from '@/utils/formatTime'
import {
  reportDataTypeOptions,
  reportDataLevelOptions,
  reportStatusOptions,
  ReportDataVO
} from '@/api/energy/report'
import { DeviceVO } from '@/api/energy/device'
import { ArrowUp, ArrowDown, InfoFilled, PieChart } from '@element-plus/icons-vue'
import {
  getEnergyStatistics,
  getEnergyTrend,
  getEnergyCompare,
  getEnergyDistribution,
  EnergyStatisticsParams
} from '@/api/energy/statistics'
import { getRefreshToken } from '@/utils/auth'
import { ElMessage, ElNotification } from 'element-plus'

// 数据类型中英文映射
const dataTypeMap: Record<string, string> = {
  currents: '电流',
  temperature: '温度',
  voltage: '电压',
  activePower: '有功功率',
  reactivePower: '无功功率',
  powerFactor: '功率因数',
  energy: '能耗'
}

// 获取数据类型的中文名称
const getDataTypeName = (type: string): string => {
  return dataTypeMap[type] || type
}

// 统计数据
const statisticsData = reactive([
  {
    title: '设备总数',
    value: '0',
    icon: 'Monitor',
    bgColor: '#ecf5ff',
    iconColor: '#409eff',
    compare: undefined
  },
  {
    title: '总能耗(kWh)',
    value: '0',
    icon: 'Lightning',
    bgColor: '#f0f9eb',
    iconColor: '#67c23a',
    compare: 0
  },
  {
    title: '今日上报数',
    value: '0',
    icon: 'DataLine',
    bgColor: '#fdf6ec',
    iconColor: '#e6a23c',
    compare: 0
  },
  {
    title: '警告数据',
    value: '0',
    icon: 'Warning',
    bgColor: '#fff8e5',
    iconColor: '#e6a23c',
    compare: 0
  },
  {
    title: '危险数据',
    value: '0',
    icon: 'CircleClose',
    bgColor: '#fef0f0',
    iconColor: '#f56c6c',
    compare: 0
  }
])

// 设备数据
const deviceOptions = ref<DeviceVO[]>([])
const deviceLoading = ref(false)
const selectedDevice = ref('')

// 报告数据
const reportList = ref<ReportDataVO[]>([])
const reportLoading = ref(false)

// 图表相关
const lineChartRef = ref(null)
const pieChartRef = ref(null)
const compareChartRef = ref(null)
const chartTimeRange = ref<'day' | 'week' | 'month' | 'year'>('week')

// 定时器ID
const refreshTimer = ref<ReturnType<typeof setInterval> | null>(null)

// WebSocket相关
const ws = ref<WebSocket | null>(null)
const webSocketConnected = ref(false)

// 建立WebSocket连接
const connectWebSocket = () => {
  try {
    // 如果已连接，则直接返回
    if (
      ws.value &&
      (ws.value.readyState === WebSocket.OPEN || ws.value.readyState === WebSocket.CONNECTING)
    ) {
      console.log('WebSocket已连接或正在连接中')
      return
    }

    // WebSocket服务地址
    const wsUrl =
      (import.meta.env.VITE_BASE_URL + '/infra/ws').replace('http', 'ws') +
      '?token=' +
      getRefreshToken()

    console.log('正在连接WebSocket:', wsUrl)
    ws.value = new WebSocket(wsUrl)

    // 连接成功
    ws.value.onopen = (event) => {
      console.log('WebSocket连接已打开:', event)
      webSocketConnected.value = true
    }

    // 连接关闭
    ws.value.onclose = (event) => {
      console.log('WebSocket连接已关闭, code:', event.code, 'reason:', event.reason, event)
      webSocketConnected.value = false

      // 5秒后尝试重新连接
      setTimeout(connectWebSocket, 5000)
    }

    // 连接错误
    ws.value.onerror = (error) => {
      console.error('WebSocket连接出错:', error)
      webSocketConnected.value = false
    }

    // 收到消息
    ws.value.onmessage = (event) => {
      handleWebSocketMessage(event.data)
    }
  } catch (error) {
    console.error('初始化WebSocket连接时出错:', error)
  }
}

// 处理WebSocket消息
const handleWebSocketMessage = (messageData: string) => {
  console.log('收到WebSocket消息:', messageData)

  // 处理心跳消息
  if (messageData === 'pong') {
    return
  }

  try {
    // 解析消息
    const jsonMessage = JSON.parse(messageData)
    console.log('解析后的消息对象:', jsonMessage)

    const type = jsonMessage.type
    console.log('消息类型:', type)

    // 处理能源报告创建的消息类型
    if (type === 'energy-report-created') {
      let content: any = null

      try {
        // 尝试解析content为对象
        if (typeof jsonMessage.content === 'string') {
          content = JSON.parse(jsonMessage.content)
        } else if (typeof jsonMessage.content === 'object') {
          content = jsonMessage.content
        }
      } catch (e) {
        console.warn('解析content失败，使用原始内容:', e)
        content = jsonMessage.content
      }

      if (!content) {
        console.warn('无法获取消息内容，尝试使用整个消息对象')
        content = jsonMessage
      }

      console.log('能源报告数据:', content)

      // 获取数据字段
      const deviceId = content.deviceId || '未知设备'
      const reportDataType = content.reportDataType || '未知类型'
      const reportDataValue = content.reportDataValue || 0

      // 获取设备名称
      const deviceName = getDeviceName(deviceId)
      // 获取数据类型显示名称
      const dataTypeName =
        getReportDataTypeLabel(reportDataType) || dataTypeMap[reportDataType] || reportDataType

      // 构建通知内容
      const dangerousMessage = `
        <div style="margin-top: 8px;">
          <div><strong>设备名称:</strong> ${deviceName}</div>
          <div><strong>设备ID:</strong> ${deviceId}</div>
          <div><strong>数据类型:</strong> ${dataTypeName}</div>
          <div><strong>数据值:</strong> <span style="font-weight: bold; color: #409EFF">${reportDataValue}</span></div>
          <div style="margin-top: 5px; color: #888; font-size: 12px;">点击查看详情</div>
        </div>
      `

      // 显示通知
      ElNotification({
        title: '新的能源报告数据已创建',
        dangerouslyUseHTMLString: true,
        message: dangerousMessage,
        type: 'success',
        duration: 8000,
        onClick: () => {
          // 点击通知时，刷新数据并滚动到报告数据区域
          getReportData()
          // 找到报告数据列表元素并滚动到视图
          setTimeout(() => {
            // 通过更可靠的方式找到报告数据区域
            const reportCards = document.querySelectorAll('.card-header')
            // 转换为数组后再循环
            Array.from(reportCards).forEach((card) => {
              if (card.textContent && card.textContent.includes('最近能耗数据上报')) {
                card.scrollIntoView({ behavior: 'smooth' })
              }
            })
          }, 300)
        }
      })
    }
  } catch (error) {
    console.error('处理WebSocket消息失败:', error, '原始消息:', messageData)
  }
}

// 发送心跳消息
const sendPing = () => {
  if (ws.value && ws.value.readyState === WebSocket.OPEN) {
    ws.value.send('ping')
  }
}

// WebSocket心跳定时器
let heartbeatTimer: number | null = null

// 关闭WebSocket连接
const closeWebSocket = () => {
  if (ws.value) {
    ws.value.close()
    ws.value = null
    webSocketConnected.value = false
  }

  if (heartbeatTimer !== null) {
    clearInterval(heartbeatTimer)
    heartbeatTimer = null
  }
}

// 获取设备列表
const loadDevices = async () => {
  deviceLoading.value = true
  try {
    const res = await getDeviceList()
    deviceOptions.value = res || []
    // 更新设备总数
    statisticsData[0].value = deviceOptions.value.length.toString()
  } catch (error) {
    console.error('获取设备列表失败', error)
  } finally {
    deviceLoading.value = false
  }
}

// 处理设备变更
const handleDeviceChange = () => {
  getReportData()
}

// 获取能耗报告数据
const getReportData = async () => {
  reportLoading.value = true
  try {
    // 获取统计数据
    const params: EnergyStatisticsParams = {
      deviceId: selectedDevice.value || undefined,
      timeRange: chartTimeRange.value
    }

    const statsData = await getEnergyStatistics(params)

    // 更新统计卡片
    statisticsData[0].value = statsData.deviceCount.toString()
    statisticsData[1].value = statsData.totalEnergy.toFixed(2)
    statisticsData[2].value = statsData.todayReportCount.toString()
    statisticsData[3].value = statsData.warningCount.toString()
    statisticsData[4].value = statsData.dangerCount.toString()

    // 更新环比数据
    if (statsData.compareRates) {
      statisticsData[1].compare = statsData.compareRates.energy
      statisticsData[2].compare = statsData.compareRates.reportCount
      statisticsData[3].compare = statsData.compareRates.warning
      statisticsData[4].compare = statsData.compareRates.danger
    }

    // 获取近期上报数据列表，用于表格显示
    const reportRes = await getReportDataPage({ pageNo: 1, pageSize: 20 })
    if (reportRes && reportRes.list) {
      reportList.value = reportRes.list
    }

    // 更新图表
    initLineChart()
    initPieChart()
    initCompareChart()
  } catch (error) {
    console.error('获取能耗数据失败', error)
  } finally {
    reportLoading.value = false
  }
}

// 工具方法：获取设备名称
const getDeviceName = (deviceId: string) => {
  const device = deviceOptions.value.find((item) => item.deviceId === deviceId)
  return device ? device.deviceName : deviceId
}

// 工具方法：获取数据类型标签
const getReportDataTypeLabel = (value: string) => {
  return reportDataTypeOptions.find((item) => item.value === value)?.label || value
}

// 工具方法：获取数据级别标签
const getReportDataLevelLabel = (value: string) => {
  return reportDataLevelOptions.find((item) => item.value === value)?.label || value
}

// 工具方法：获取数据级别类型（用于标签颜色）
const getReportDataLevelType = (value: string) => {
  return reportDataLevelOptions.find((item) => item.value === value)?.type || ''
}

// 工具方法：获取环比样式类
const getCompareClass = (value: number) => {
  return value > 0 ? 'compare-up' : value < 0 ? 'compare-down' : ''
}

// 处理图表时间范围变更
const handleChartRangeChange = () => {
  getReportData()
}

// 初始化折线图
const initLineChart = async () => {
  if (!lineChartRef.value) return

  // 获取趋势数据
  const params: EnergyStatisticsParams = {
    deviceId: selectedDevice.value || undefined,
    timeRange: chartTimeRange.value
  }

  try {
    const trendData = await getEnergyTrend(params)

    // 按数据类型分组
    const dataByType: Record<string, { time: string; value: number }[]> = {}
    const timeLabels: string[] = []

    // 处理数据
    trendData.forEach((item) => {
      // 收集时间标签
      if (!timeLabels.includes(item.time)) {
        timeLabels.push(item.time)
      }

      // 按类型分组
      if (!dataByType[item.dataType]) {
        dataByType[item.dataType] = []
      }

      dataByType[item.dataType].push({
        time: item.time,
        value: item.value
      })
    })

    // 时间标签排序
    timeLabels.sort()

    // 准备图表数据
    const series = Object.keys(dataByType).map((type) => {
      // 确保每个时间点都有数据
      const data = timeLabels.map((time) => {
        const point = dataByType[type].find((item) => item.time === time)
        return point ? point.value : 0
      })

      return {
        name: getDataTypeName(type),
        type: 'line',
        data: data,
        smooth: true
      }
    })

    const lineChart = echarts.init(lineChartRef.value)

    const option = {
      title: {
        text: selectedDevice.value
          ? `${getDeviceName(selectedDevice.value)}能耗趋势`
          : '能耗数据趋势'
      },
      tooltip: {
        trigger: 'axis'
      },
      legend: {
        data: Object.keys(dataByType).map((type) => getDataTypeName(type))
      },
      grid: {
        left: '3%',
        right: '4%',
        bottom: '3%',
        containLabel: true
      },
      xAxis: {
        type: 'category',
        boundaryGap: false,
        data: timeLabels
      },
      yAxis: {
        type: 'value'
      },
      series: series
    }

    lineChart.setOption(option)

    // 监听窗口大小变化，调整图表大小
    window.addEventListener('resize', () => {
      lineChart.resize()
    })
  } catch (error) {
    console.error('获取能耗趋势数据失败', error)
  }
}

// 初始化环比图表
const initCompareChart = async () => {
  if (!compareChartRef.value) return

  // 获取环比数据
  const params: EnergyStatisticsParams = {
    deviceId: selectedDevice.value || undefined,
    timeRange: chartTimeRange.value
  }

  try {
    const compareData = await getEnergyCompare(params)

    // 准备图表数据
    const categories: string[] = []
    const currentValues: number[] = []
    const previousValues: number[] = []
    const changeRates: number[] = []

    compareData.forEach((item) => {
      categories.push(getDataTypeName(item.dataType))
      currentValues.push(Number(item.currentValue))
      previousValues.push(Number(item.previousValue))
      changeRates.push(Number(item.changeRate))
    })

    // 周期名称
    let periodName = '周'
    if (chartTimeRange.value === 'day') {
      periodName = '日'
    } else if (chartTimeRange.value === 'month') {
      periodName = '月'
    } else if (chartTimeRange.value === 'year') {
      periodName = '年'
    }

    const compareChart = echarts.init(compareChartRef.value)

    const option = {
      title: {
        text: selectedDevice.value
          ? `${getDeviceName(selectedDevice.value)}能耗环比分析`
          : '能耗环比分析'
      },
      tooltip: {
        trigger: 'axis',
        axisPointer: {
          type: 'shadow'
        },
        formatter: function (params: any) {
          const idx = params[0].dataIndex
          return `${categories[idx]}<br/>
                  本${periodName}: ${currentValues[idx].toFixed(2)}<br/>
                  上${periodName}: ${previousValues[idx].toFixed(2)}<br/>
                  环比变化: ${changeRates[idx].toFixed(2)}%`
        }
      },
      legend: {
        data: [`本${periodName}`, `上${periodName}`, '环比变化(%)']
      },
      grid: {
        left: '3%',
        right: '4%',
        bottom: '3%',
        containLabel: true
      },
      xAxis: {
        type: 'category',
        data: categories
      },
      yAxis: [
        {
          type: 'value',
          name: '能耗值',
          position: 'left'
        },
        {
          type: 'value',
          name: '变化率(%)',
          position: 'right',
          axisLine: {
            show: true,
            lineStyle: {
              color: '#675bba'
            }
          },
          axisLabel: {
            formatter: '{value}%'
          }
        }
      ],
      series: [
        {
          name: `本${periodName}`,
          type: 'bar',
          data: currentValues.map((v) => v.toFixed(2))
        },
        {
          name: `上${periodName}`,
          type: 'bar',
          data: previousValues.map((v) => v.toFixed(2))
        },
        {
          name: '环比变化(%)',
          type: 'line',
          yAxisIndex: 1,
          data: changeRates.map((v) => v.toFixed(2)),
          symbol: 'circle',
          symbolSize: 8,
          itemStyle: {
            color: '#675bba'
          },
          lineStyle: {
            width: 2
          }
        }
      ]
    }

    compareChart.setOption(option)

    // 监听窗口大小变化，调整图表大小
    window.addEventListener('resize', () => {
      compareChart.resize()
    })
  } catch (error) {
    console.error('获取能耗环比数据失败', error)
  }
}

// 初始化饼图
const initPieChart = async () => {
  if (!pieChartRef.value) return

  // 获取分布数据
  const params: EnergyStatisticsParams = {
    deviceId: selectedDevice.value || undefined,
    timeRange: chartTimeRange.value
  }

  try {
    const distributionData = await getEnergyDistribution(params)

    // 转换为饼图数据格式
    const pieData = distributionData.map((item) => ({
      name: item.name.includes('_')
        ? getDataTypeName(item.name.split('_')[0]) + '_' + item.name.split('_')[1]
        : getDataTypeName(item.name),
      value: Number(item.value)
    }))

    const pieChart = echarts.init(pieChartRef.value)

    const option = {
      title: {
        text: selectedDevice.value
          ? `${getDeviceName(selectedDevice.value)}能耗分布`
          : '设备能耗分布',
        left: 'center'
      },
      tooltip: {
        trigger: 'item',
        formatter: '{a} <br/>{b} : {c} kWh ({d}%)'
      },
      legend: {
        orient: 'vertical',
        left: 'left',
        top: 'middle',
        type: 'scroll',
        data: pieData.map((item) => item.name)
      },
      series: [
        {
          name: '设备能耗',
          type: 'pie',
          radius: '55%',
          center: ['60%', '50%'],
          data: pieData,
          emphasis: {
            itemStyle: {
              shadowBlur: 10,
              shadowOffsetX: 0,
              shadowColor: 'rgba(0, 0, 0, 0.5)'
            }
          },
          label: {
            formatter: '{b}: {c} kWh ({d}%)'
          }
        }
      ]
    }

    pieChart.setOption(option)

    // 监听窗口大小变化，调整图表大小
    window.addEventListener('resize', () => {
      pieChart.resize()
    })
  } catch (error) {
    console.error('获取能耗分布数据失败', error)
  }
}

// 启动定时刷新
const startRefreshTimer = () => {
  // 清除可能存在的旧定时器
  if (refreshTimer.value !== null) {
    clearInterval(refreshTimer.value)
  }

  // 设置新的定时器，每10秒执行一次
  refreshTimer.value = setInterval(() => {
    getReportData()
  }, 10000) // 10000毫秒 = 10秒
}

// 停止定时刷新
const stopRefreshTimer = () => {
  if (refreshTimer.value !== null) {
    clearInterval(refreshTimer.value)
    refreshTimer.value = null
  }
}

onMounted(() => {
  loadDevices().then(() => {
    getReportData()
  })

  // 启动定时刷新
  startRefreshTimer()

  // 建立WebSocket连接
  connectWebSocket()
})

onUnmounted(() => {
  // 组件卸载时清除定时器
  stopRefreshTimer()

  // 关闭WebSocket连接
  closeWebSocket()
})
</script>

<style lang="scss" scoped>
.dashboard-container {
  padding: 15px;

  .mb-20 {
    margin-bottom: 20px;
  }

  .statistics-row {
    display: flex;
    flex-wrap: nowrap;
    margin: 0 -10px;
  }

  .statistics-item {
    flex: 1;
    padding: 0 10px;
    width: 20%; /* 默认5个卡片，每个占20% */
    box-sizing: border-box;
  }

  .card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;

    .el-icon {
      margin-left: 8px;
      cursor: pointer;
      font-size: 16px;
      color: #909399;
    }
  }

  .chart-tabs {
    margin-right: 10px;
  }

  .filter-container {
    display: flex;
    align-items: center;

    .filter-label {
      margin-right: 10px;
      font-weight: bold;
    }
  }

  .statistics-card {
    display: flex;
    align-items: center;
    padding: 10px;
    height: 100%;

    .icon-container {
      width: 48px;
      height: 48px;
      border-radius: 8px;
      display: flex;
      align-items: center;
      justify-content: center;
      margin-right: 12px;
      flex-shrink: 0;
    }

    .content {
      flex: 1;
      min-width: 0;

      .title {
        font-size: 14px;
        color: #909399;
        margin-bottom: 5px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
      }

      .value {
        font-size: 20px;
        font-weight: bold;
        color: #303133;
        margin-bottom: 5px;
      }

      .compare-text {
        font-size: 12px;
        display: flex;
        align-items: center;

        &.compare-up {
          color: #f56c6c;
        }

        &.compare-down {
          color: #67c23a;
        }
      }
    }
  }
}
</style>
